﻿using Microsoft.Extensions.Logging;
using NETCore.MailKit.Core;
using NETCore.MailKit.Infrastructure.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using XXX.Common;

namespace XXX.Bo
{
    public class SendEmailService 
    {
        private readonly IEmailService _emailService;
        private readonly ILogger _logger;
        public SendEmailService(IEmailService emailService, ILogger logger)
        {
            _emailService = emailService;
            _logger = logger;
        }
        /// <summary>
        /// 在用的邮件服务
        /// </summary>
        /// <param name="sendcope">发送范围： N: 不发送，ALL，全部，ERROR，只发送失败的</param>
        /// <param name="retcode">当前code值</param>
        /// <param name="mailTo"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <param name="isHtml"></param>
        /// <param name="sender"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void Send(string sendcope,int retcode, string mailTo, string subject, string message, bool isHtml = false, SenderInfo sender = null)
        {
            try
            {
                //失败，邮件才发送，或者全部发送
                if ((sendcope == "ERROR"  && retcode !=200)|| sendcope == "ALL")
                {
                    _emailService.Send(mailTo, subject, message, isHtml, sender);
                    _logger.LogDebug("邮件已发送！" + mailTo+":"+subject);
                }
                else
                {
                    return;
                }
              
            }
            catch(Exception ex)
            {
                _logger.LogDebug("发送邮件错误！"+ex.Message);
                return;
            }
            
        }

        
    }
}
